#ifndef TESTNETWORKEVENT_H
#define TESTNETWORKEVENT_H

#include "NetworkEvents.h"
#include <utils/String.h>

class TestClientEvent : public RegisteredClientEvent<TestClientEvent>
{
	
public:
	
	TestClientEvent( ) {}
	TestClientEvent( String sData ) : m_sData( sData ) {}
	
protected:
	
	//Called when the event is activated locally
    virtual void onActivate()
    {
		std::cout << "TestClientEvent::activate(), m_sData = " << m_sData << std::endl;
	}
    
    //Called when responding to the received remote event
    //virtual void onRespond() = 0;
    
    //Override to write all the event's data to a bitstream and return it
    virtual void encode(RakNet::BitStream& bsEvent)
    {
		//double d = 3.141592;
		//bsEvent.Write( d );
		bsEvent.Write( (int)m_sData.length() + 1 );
		bsEvent.Write( m_sData.c_str(), m_sData.length() + 1 );
	}
    
    //Override to read all the event's data from the given bitstream
    virtual void decode(RakNet::BitStream& bsData)
    {
		int length = 0;
		bsData.Read( length );
		char* cpTmp = new char[length];
		bsData.Read( cpTmp, length );
		m_sData = cpTmp;
		delete [] cpTmp;
		//double d;
		//bsData.Read( d );
		//std::cout << "Decoded d = " << d << std::endl;
	}
    
private:
	
	String m_sData;
	
};

class TestServerEvent : public RegisteredServerEvent<TestServerEvent>
{
	
public:
	
	TestServerEvent( ) {}
	TestServerEvent( String sData ) : m_sData( sData ) {}
	
protected:
	
	//Called when the event is activated locally
    virtual void onActivate()
    {
		std::cout << "TestServerEvent::activate(), m_sData = " << m_sData << std::endl;
	}
    
    //Called when responding to the received remote event
    //virtual void onRespond() = 0;
    
    //Override to write all the event's data to a bitstream and return it
    virtual void encode(RakNet::BitStream& bsEvent)
    {
		//double d = 3.141592;
		//bsEvent.Write( d );
		bsEvent.Write( (int)m_sData.length() + 1 );
		bsEvent.Write( m_sData.c_str(), m_sData.length() + 1 );
	}
    
    //Override to read all the event's data from the given bitstream
    virtual void decode(RakNet::BitStream& bsData)
    {
		int length = 0;
		bsData.Read( length );
		char* cpTmp = new char[length];
		bsData.Read( cpTmp, length );
		m_sData = cpTmp;
		delete [] cpTmp;
		//double d;
		//bsData.Read( d );
		//std::cout << "Decoded d = " << d << std::endl;
	}
    
private:
	
	String m_sData;
	
};

#endif //TESTNETWORKEVENT_H
